/*
 * JeggtimerApp.java
 */

package jeggtimer;

import org.jdesktop.application.Application;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;

/**
 * The main class of the application.
 */
public class JeggtimerApp extends SingleFrameApplication {
    private static Ticker t;
    static JeggtimerView view;
    /**
     * At startup create and show the main frame of the application.
     */
    @Override protected void startup() {
        t=new Ticker();
        view = new JeggtimerView(this,t);
        show(view);
        t.setView(view);
    }

    /**
     * This method is to initialize the specified window by injecting resources.
     * Windows shown in our application come fully initialized from the GUI
     * builder, so this additional configuration is not needed.
     */
    @Override protected void configureWindow(java.awt.Window root) {
    }

    /**
     * A convenient static getter for the application instance.
     * @return the instance of JeggtimerApp
     */
    public static JeggtimerApp getApplication() {
        return Application.getInstance(JeggtimerApp.class);
    }

    /**
     * Main method launching the application.
     */
    public static void main(String[] args) {
        launch(JeggtimerApp.class, args);
    }
    public static void go(ResourceMap resourceMap){
        if(t.going()){
            t.stop(view.getResourceMap());
            view.getjButton1().setIcon(resourceMap.getIcon("startButton.icon"));
        }
        else{
            t.setMin(Integer.parseInt(view.getJTextField1().getText()));
            t.setSec(Integer.parseInt(view.getJTextField2().getText()));
            TickerTask tt=new TickerTask();
            tt.setTicker(JeggtimerApp.t);
            tt.setView(view);
            t.timer.scheduleAtFixedRate(tt, 10, 1000);
            t.setGoing(true);
            view.getjButton1().setIcon(resourceMap.getIcon("startButton.disabledIcon"));
        }
    }
}
